package com.atguigu.ggkt.vod.controller;



import com.atguigu.ggkt.result.Result;
import com.atguigu.ggkt.vo.vod.ChapterVo;
import com.atguigu.ggkt.model.vod.Chapter;

import com.atguigu.ggkt.vod.service.ChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author sleephardzz
 * @since 2023-07-10
 */
@RestController
@RequestMapping(value="/admin/vod/chapter")
//@CrossOrigin
public class ChapterController {

    @Autowired
    private ChapterService chapterService;

    //1查询大纲列表list
    @GetMapping("getNestedTreeList/{courseId}")
    public Result getTreeList(@PathVariable Long courseId){
        List<ChapterVo> list =  chapterService.getTreeList(courseId);
        return Result.ok(list);
    }

    //2添加章节
    @PostMapping("save")
    public Result save(@RequestBody Chapter chapter){
        chapterService.save(chapter);
        return Result.ok(null);
    }

    //3根据id查询
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id){
        Chapter chapter = chapterService.getById(id);
        return Result.ok(chapter);
    }

    //4修改实现
    @PostMapping("update")
    public Result update(@RequestBody Chapter chapter){
        boolean success = chapterService.updateById(chapter);
        return Result.ok(success);
    }
    //5删除
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable String id){
        boolean success = chapterService.removeById(id);
        return Result.ok(success);
    }
}

